//
//  QRCodeViewController.swift
//  SwiftSina
//
//  Created by 七 on 2017/4/20.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit
import AVFoundation
class QRCodeViewController: UIViewController,UITabBarDelegate {
    @IBOutlet weak var QRCTabbar: UITabBar!
///冲击波视图顶部约束
    @IBOutlet weak var scanLinCons: NSLayoutConstraint!
    ///容器的高度约束
    @IBOutlet weak var containerHeihtCons: NSLayoutConstraint!
    ///冲击波视图
    @IBOutlet weak var scanView: UIImageView!
    
    lazy var session: AVCaptureSession = AVCaptureSession()
    lazy var deviceInput: AVCaptureDeviceInput? = {
        //获取摄像头
        let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
        let input = try? AVCaptureDeviceInput(device: device)
        return input
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        QRCTabbar.selectedItem = QRCTabbar.items?[0]
        QRCTabbar.delegate = self
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        startAnimation()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //MARK:- tabbar点击
    func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        //1.修改容器高度
        if item.tag == 1 {
            containerHeihtCons.constant = 300
        }else{
            containerHeihtCons.constant = 150
        }
        //停止动画
        scanView.layer.removeAllAnimations()
        //开始动画
        startAnimation()
    }
  
    func startAnimation(){
        self.scanLinCons.constant = -self.containerHeihtCons.constant
        self.scanView.layoutIfNeeded()
        //执行冲击波动画
        UIView.animate(withDuration: 2.0, animations: {
            self.scanLinCons.constant = self.containerHeihtCons.constant
            UIView.setAnimationRepeatCount(MAXFLOAT)
            //强制更新界面
            self.scanView.layoutIfNeeded()
        }, completion: nil)
    }
    @IBAction func closeClick(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }

    @IBOutlet weak var photoLibraryClick: UIBarButtonItem!
}
